package com.zte.leave.control;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.zte.leave.model.Absence;
import com.zte.leave.model.Leave;
import com.zte.leave.service.ILeaveService;
import com.zte.user.model.Student;
import com.zte.user.model.Teacher;
import com.zte.user.model.Users;
import com.zte.user.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.Date;
import java.util.List;

@Controller
@RequestMapping("/leave")
public class LeaveAction {
    @Autowired
    private ILeaveService service;

    @RequestMapping("/insert")
    @ResponseBody
    //String leaveid,String leaveperson,Date leavetime,Date starttime,String leavereson
    public boolean insert(HttpSession session,Leave leave){
        System.out.println(leave);
        Leave leave1=new Leave(leave.getLeaveid(),leave.getLeaveperson(),leave.getLeavetime(),leave.getStarttime(),leave.getLeavereson());
        boolean b = false;
        b = service.insertLeave(leave1);
        return b;
    }

    @RequestMapping("/insertabsence")
    @ResponseBody
    //String leaveid,String leaveperson,Date leavetime,Date starttime,String leavereson
    public boolean insertabsence(HttpSession session, Absence absence){
        System.out.println(absence);
        absence.setStatus("1");
        boolean b=false;
        b = service.insertAbsence(absence);
        return b;
    }

    @RequestMapping("/select")
    @ResponseBody
    //String leaveid,String leaveperson,Date leavetime,Date starttime,String leavereson
    public List<Leave> select(HttpSession session,Leave leave){
        System.out.println(leave);
//        Leave leave1=new Leave(leave.getLeaveid(),leave.getLeaveperson(),leave.getLeavetime(),leave.getStarttime(),leave.getLeavereson());
//        boolean b = false;
        List<Leave> allLeave = service.findAllLeave(leave);
        return allLeave;
    }
    @RequestMapping("/selectabsence")
    @ResponseBody
    //String leaveid,String leaveperson,Date leavetime,Date starttime,String leavereson
    public List<Absence> selectabsence(HttpSession session,Absence absence){
//        System.out.println(leave);
//        Leave leave1=new Leave(leave.getLeaveid(),leave.getLeaveperson(),leave.getLeavetime(),leave.getStarttime(),leave.getLeavereson());
//        boolean b = false;
        List<Absence> allAbsence = service.findAllAbsence(absence);

        return allAbsence;
    }



}
